package com.liwang.lanouhn.nvshengo.activities;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.liwang.lanouhn.nvshengo.R;
import com.squareup.picasso.Picasso;
import com.tencent.tauth.Tencent;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by lanouhn on 2016/10/24.
 */
public class SetActivity extends AppCompatActivity {
    private ImageView iv_back;
    private TextView tv_feature_title;
    private RelativeLayout rl_quit;
    private Tencent mTencent;
    private CircleImageView iv_portrait;
    private TextView tv_username;
    private SharedPreferences sharedPreferences;
     private SharedPreferences.Editor personEditor;
    private SharedPreferences sp;
    private SharedPreferences.Editor editor1;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        int flag= WindowManager.LayoutParams.FLAG_FULLSCREEN;
        Window window=getWindow();
        window.setFlags(flag,flag);
        setContentView(R.layout.activity_set);
        initView();
    }

    private void initView() {
        mTencent = Tencent.createInstance("1105689916", getApplicationContext());
        sharedPreferences = getSharedPreferences("person",MODE_PRIVATE);
        personEditor=sharedPreferences.edit();
        sp = getSharedPreferences("login", MODE_PRIVATE);
        editor1 = sp.edit();
        iv_portrait= (CircleImageView) findViewById(R.id.iv_portrait);
        tv_username= (TextView) findViewById(R.id.tv_username);
        iv_back = (ImageView) findViewById(R.id.iv_back);
        tv_feature_title = (TextView) findViewById(R.id.tv_feature_title);
        rl_quit = (RelativeLayout) findViewById(R.id.rl_quit);
        tv_username.setText(sharedPreferences.getString("name", "峰"));
        Picasso.with(SetActivity.this).load(sharedPreferences.getString("icon", "")).into(iv_portrait);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        rl_quit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mTencent.logout(SetActivity.this);
                personEditor.clear();
                personEditor.commit();
                editor1.putBoolean("isLogin",false);
                editor1.commit();
                finish();

            }
        });

    }
}
